﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace hasApopo.algorithm
{
    class RSAalgorithm
    {

        public RSAalgorithm()
        {

        }

        public static BigInteger gcd(BigInteger x, BigInteger y)
        {
            if (y == 0) return x;
            else return gcd(y, x % y);
        }

        public static bool isPrime(BigInteger p)
        {
            BigInteger limit = (BigInteger)Math.Sqrt((double)p) + 1;
            BigInteger i = 2;

            while (i <= limit)
            {
                if (p % i == 0) return false;
                else ++i;
            }

            return true;
        }

        public static  byte[] EnkripDekrip(byte[] filebyte, String exp, String mod)
        {
            BigInteger expBI = BigInteger.Parse(exp);
            BigInteger modBI = BigInteger.Parse(mod);
            byte[] hasilbyte = new byte[filebyte.Length*2];

            for (int i = 0; i < filebyte.Length; i++)
            {
                BigInteger teks = new BigInteger(filebyte[i]);
                BigInteger hasil = BigInteger.ModPow(teks,expBI, modBI);
                hasilbyte[i] = (byte)hasil;            
            }

            return hasilbyte;
        }


    }


}
